import { Subject } from '../node_modules/rxjs'

export const Conversion = {
    loginEnglish:(value)=>{
        switch (value){
            case "登录":
                return "login";
            case "注册":
                return "regist";
            case "返回":
                return "back";
        }
    }
};

export const baseEmit = new Subject();

export class Methods{
    loadImg(cla){
        //加载图片
        let input = cla,imgArr = [],
            result,div;
        if(typeof FileReader==='undefined'){
            result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
            input.setAttribute('disabled','disabled');
        }else{
            input.addEventListener('change',readFile,false);
        }
        function readFile() {
            for (let i = 0; i < this.files.length; i++) {
                if (!input['value'].match(/.jpg|.gif|.png|.bmp/i)) {　　//判断上传文件格式
                    return alert("上传的图片格式不正确，请重新选择")
                }
                let reader = new FileReader();
                reader.readAsDataURL(this.files[i]);
                reader.onload = function (e) {
                    result = '<div id="result"><img class="x-images" src="' + this.result + '" alt=""/></div>';
                    div = document.createElement('div');
                    div.innerHTML = result;
                    document.querySelector('.x-image-menu').appendChild(div);  　　//插入dom树
                    imgArr.push(this.result);
                }
            }
            baseEmit.next(imgArr);
        }
    }
}